package com.zzw.basic.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

public class ReadFile {
	
	public static void main(String[] args) throws IOException {
		FileInputStream fis = new FileInputStream("../ReflectDemo/src/main/java/com/zzw/io/ReadFile.java");
		FileChannel channel = fis.getChannel();
		ByteBuffer buffer = ByteBuffer.allocate(256);
		while(channel.read(buffer) != -1){
			buffer.flip();
			Charset charset = Charset.forName("GBK");
			CharsetDecoder decoder = charset.newDecoder();
			CharBuffer cbBuffer = decoder.decode(buffer);
			System.out.println(cbBuffer);
			buffer.clear();
		}
	}
}
